import Vue from 'vue';
import Router from 'vue-router';

import Login from '@/view/login/index'
import List from '../components/list'
import Mine from '@/view/mine/mine'
import MyInfo from '@/view/mine/myInfo'
import Coupon from '@/view/mine/coupon'
import CouponShop from '@/view/mine/couponShop'
import FocusShop from '@/view/mine/focusShop'
import Shop from '@/view/mine/shop'
import ShopDetail from '@/view/mine/shopDetail'
import Integral from '@/view/mine/integral'
import Authorization from '@/view/authorization/index'
import Activity from '@/view/activity/index'
import Registered from '@/view/registered/index'
import ExchangeCuopon from '@/view/mine/exchangeCuopon'
import ApplyIntegral from '@/view/mine/applyIntegral'
import ApplyIntegralList from '@/view/mine/applyIntegralList'
import UpdatePassword from '@/view/mine/updatePassword'
import ShopBill from '@/view/mine/shopBill'
import ShopBillDetail from '@/view/mine/shopBillDetail'
import ShopMap from '@/view/mine/shopMap'
import ShopRegistered from '@/view/registered/shop'
import MyShopInfo from '@/view/mine/myShopInfo'
import Empty from '@/view/login/empty'
import IntegralMange from '@/view/mine/integralMange'
import MemberNotice from '@/view/mine/memberNotice'


Vue.use(Router);

const routes = [
  {
    path: '/',
    name: 'Mine',
    component: Mine,
    meta:{
      title:'',
      keepAlive:false
    }
  },
  {
    path: '/list',
    name: 'list',
    component: List,
    children: [
          
    ]
  },
  {
    path: '/mine',
    name: 'mine',
    component: Mine,
    meta:{
      title:'',
      keepAlive:false
    }
  },
  {
    path: '/login',
    name: 'login',
    component: Login,
    meta:{
      title:'登录'
    }
  },
  {
    path: '/myInfo',
    name: 'myInfo',
    component: MyInfo,
    meta:{
      title:'我的信息',
      keepAlive:false
    }
  },
  {
    path: '/coupon',
    name: 'coupon',
    component: Coupon,
    meta:{
      title:'商城优惠券'
    }
  },
  {
    path: '/couponShop',
    name: 'couponShop',
    component: CouponShop,
    meta:{
      title:'店铺优惠券'
    }
  },
  {
    path: '/focusShop',
    name: 'focusShop',
    component: FocusShop,
    meta:{
      title:'关注的店铺'
    }
  },
  {
    path: '/shop',
    name: 'shop',
    component: Shop,
    meta:{
      title:'查找店铺'
    }
  },
  {
    path: '/shopDetail',
    name: 'shopDetail',
    component: ShopDetail,
    meta:{
      title:'店铺详情'
    }
  },
  {
    path: '/integral',
    name: 'integral',
    component: Integral,
    meta:{
      title:'积分流水记录'
    }
  },
  {
    path: '/authorization',
    name: 'authorization',
    component: Authorization,
    meta:{
      title:'上海井亭生活广场'
    }
  },
  {
    path: '/activity',
    name: 'activity',
    component: Activity,
    meta:{
      title:'商场活动'
    }
  },
  {
    path: '/registered',
    name: 'registered',
    component: Registered,
    meta:{
      title:'用户注册'
    }
  },
  {
    path: '/exchangeCuopon',
    name: 'exchangeCuopon',
    component: ExchangeCuopon,
    meta:{
      title:'兑换优惠券'
    }
  },
  {
    path: '/applyIntegral',
    name: 'applyIntegral',
    component: ApplyIntegral,
    meta:{
      title:'账单核算积分申请'
    }
  },
  {
    path: '/applyIntegralList',
    name: 'applyIntegralList',
    component: ApplyIntegralList,
    meta:{
      title:'积分核算'
    }
  },
  {
    path: '/integralMange',
    name: 'integralMange',
    component: IntegralMange,
    meta:{
      title:'积分管理'
    }
  },
  {
    path: '/updatePassword',
    name: 'updatePassword',
    component: UpdatePassword,
    meta:{
      title:'修改密码'
    }
  },
  {
    path: '/shopBill',
    name: 'shopBill',
    component: ShopBill,
    meta:{
      title:'账单列表'
    }
  },
  {
    path: '/shopBillDetail',
    name: 'shopBillDetail',
    component: ShopBillDetail,
    meta:{
      title:'账单明细'
    }
  },
  {
    path: '/shopMap',
    name: 'shopMap',
    component: ShopMap,
    meta:{
      title:'店铺位置'
    }
  },
  {
    path: '/shopRegistered',
    name: 'shopRegistered',
    component: ShopRegistered,
    meta:{
      title:'商家入驻'
    }
  },
  {
    path: '/myShopInfo',
    name: 'myShopInfo',
    component: MyShopInfo,
    meta:{
      title:'我的信息',
      keepAlive:false
    }
  },
  {
    path: '/memberNotice',
    name: 'memberNotice',
    component: MemberNotice,
    meta:{
      title:'会员须知',
      keepAlive:false
    }
  },
  {
    path: '/empty',
    name: 'empty',
    component: Empty,
    meta:{
      title:'登录'
    }
  }
];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});

const router = new Router({ routes });

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  console.log(from)
  // if(to.name == 'mine' && from.name == 'login'){
  //   to.meta.keepAlive = false;
  // }else{
  //   to.meta.keepAlive = true;
  // }
  next();
});

export {
  router
};